package base

import (
	"fmt"
	"unsafe"
)

func DataType() {
	// 有符号整形
	var a int = 1
	fmt.Printf("%T: %d \n", a, unsafe.Sizeof(a))
	var b int8 = 2
	fmt.Printf("%T: %d \n", b, unsafe.Sizeof(b))
	var c int16 = 3
	fmt.Printf("%T: %d \n", c, unsafe.Sizeof(c))
	var d int32 = 4
	fmt.Printf("%T: %d \n", d, unsafe.Sizeof(d))
	var e int64 = 5
	fmt.Printf("%T: %d \n", e, unsafe.Sizeof(e))
	// 无符号整形
	var ua uint = 1
	fmt.Printf("%T: %d \n", ua, unsafe.Sizeof(ua))
	var ub uint8 = 2
	fmt.Printf("%T: %d \n", ub, unsafe.Sizeof(ub))
	var uc uint16 = 3
	fmt.Printf("%T: %d \n", uc, unsafe.Sizeof(uc))
	var ud uint32 = 4
	fmt.Printf("%T: %d \n", ud, unsafe.Sizeof(ud))
	var ue uint64 = 5
	fmt.Printf("%T: %d \n", ue, unsafe.Sizeof(ue))
	// 等价int32，表示一个unicode编码
	var ra rune = 1
	fmt.Printf("%T: %d \n", ra, unsafe.Sizeof(ra))

	// 浮点数 = 符号位 + 指数位 + 尾数位
	// 精度类型
	var fa float32 = 1.1
	fmt.Printf("%T: %d \n", fa, unsafe.Sizeof(fa))
	var fb float64 = 1.2
	fmt.Printf("%T: %d \n", fb, unsafe.Sizeof(fb))

	// 等价 unit8，存储字符时一般选用
	// 字符类型
	var b1 byte = 'a'
	fmt.Printf("%T: %d \n", b1, unsafe.Sizeof(b1))

	var bool1 bool = true
	fmt.Printf("%T: %d \n", bool1, unsafe.Sizeof(bool1))

	// 默认值
	var int9 int
	var float9 float32
	var bool9 bool
	fmt.Println(int9, float9, bool9)

	// 类型转换
	fmt.Println(float64(int9))
}
